import * as DT from 'dt-sdk/library/DT'
import { viewer } from '@/components/dt-scene/index.vue'
import Plot from '@/utils/plotsUnit/plotsUnit.js'
let plotHandler = null
export default {
  name: 'plot',
  // inject: ['sceneStatus'],
  data() {
    return {
      checkbox: true,
      type: '',
      color: 'rgba(18, 148, 241,1)',
      plotArr: [
        {
          type: '点',
          img: 'static/plot/point.png'
        },
        {
          type: '线',
          img: 'static/plot/x.png'
        },
        {
          type: '曲线',
          img: 'static/plot/qx.png'
        },
        {
          type: '圆',
          img: 'static/plot/yx.png'
        },
        {
          type: '矩形',
          img: 'static/plot/jx.png'
        },
        {
          type: '多边形',
          img: 'static/plot/dbx.png'
        },
        {
          type: '攻击箭头',
          img: 'static/plot/gjjt.png'
        },
        // {
        //   type: '钳击箭头',
        //   img: 'static/plot/qjjt.png'
        // },
        {
          type: '文字',
          img: 'static/plot/point.png'
        }
      ],
      currentSelect: -1,
      plot: null,
      popoverSpan: ''
    }
  },
  watch: {
    // sceneStatus: {
    //   handler(val) {
    //     val.isInited && this.initPlot(viewer, DT.Cesium)
    //   },
    //   immediate: true,
    //   deep: true
    // },
  },
  mounted() {
    this.initPlot(viewer, DT.Cesium)
  },
  methods: {
    /**
     * checkbox 勾选方法
     * @author wzw
     * @date 2021-10-26
     * @param {any} flag
     * @returns {any}
     */
    checkboxChange(flag) {
      this.checkbox = flag
      this.destroy(1)
    },
    /**
     * 颜色变化
     * @author wzw
     * @date 2021-10-27
     * @returns {any}
     */
    colorChange() {
      this.destroy(1)
    },
    /**k
     * 勾选项
     * @author wzw
     * @date 2021-10-26
     * @param {String} type
     * @param {Number} index
     * @returns {any}
     */
    selectPlot(type, index) {
      this.currentSelect = index

      plotHandler.DrawCreate({
        type: type,
        flag: this.checkbox,
        color: this.color,
        outLineColor: this.color
      })
    },

    // 清除标绘事件等
    destroy(type) {
      if (type !== 2) {
        this.currentSelect = -1
      }
      if (type === 1) { //取消绘制
        plotHandler.destroy()
      } else if (type === 2) { //选择清除
        plotHandler.selectrClear()
      } else { //清除标绘
        plotHandler.clear()
      }
    },
    /**
     * 初始化标绘功能
     * @author wzw
     * @date 2021-10-25
     * @param {any} viewer
     * @param {any} Cesium
     * @returns {any}
     */
    initPlot(viewer, Cesium) {
      // 初始化标绘
      plotHandler = new Plot({
        viewer: viewer,
        Cesium: Cesium
      })
    },

    /**
     * 文字标绘
     * @author wzw
     * @date 2021-10-25
     * @returns {any}
     */
    popoverBtn() {
      plotHandler._DrawText.createText(this.popoverSpan)
      this.popoverSpan = ""
    },

  },
}